"""peding user

Revision ID: 16b9298da669
Revises: 
Create Date: 2024-06-14 18:47:16.993734

"""

from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql

# revision identifiers, used by Alembic.
revision: str = "16b9298da669"
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table("specialization")
    op.drop_table("address")
    op.drop_index("token", table_name="email_token")
    op.drop_table("email_token")
    op.drop_index("email", table_name="user")
    op.drop_index("username", table_name="user")
    op.drop_table("user")
    op.drop_table("examination")
    op.drop_index("email", table_name="pending_user")
    op.drop_index("token", table_name="pending_user")
    op.drop_index("username", table_name="pending_user")
    op.drop_table("pending_user")
    op.drop_table("schedule_record")
    op.drop_table("doctor")
    op.drop_table("doctor_specialization")
    op.drop_index("name", table_name="role")
    op.drop_table("role")
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "role",
        sa.Column("id", mysql.INTEGER(), autoincrement=True, nullable=False),
        sa.Column("name", mysql.VARCHAR(length=50), nullable=False),
        sa.PrimaryKeyConstraint("id"),
        mysql_collate="utf8mb4_0900_ai_ci",
        mysql_default_charset="utf8mb4",
        mysql_engine="InnoDB",
    )
    op.create_index("name", "role", ["name"], unique=True)
    op.create_table(
        "doctor_specialization",
        sa.Column(
            "doctor_id", mysql.INTEGER(), autoincrement=False, nullable=True
        ),
        sa.Column(
            "specialization_id",
            mysql.INTEGER(),
            autoincrement=False,
            nullable=True,
        ),
        sa.ForeignKeyConstraint(
            ["doctor_id"], ["doctor.id"], name="doctor_specialization_ibfk_1"
        ),
        sa.ForeignKeyConstraint(
            ["specialization_id"],
            ["specialization.id"],
            name="doctor_specialization_ibfk_2",
        ),
        mysql_collate="utf8mb4_0900_ai_ci",
        mysql_default_charset="utf8mb4",
        mysql_engine="InnoDB",
    )
    op.create_table(
        "doctor",
        sa.Column("id", mysql.INTEGER(), autoincrement=True, nullable=False),
        sa.Column("last_name", mysql.VARCHAR(length=50), nullable=False),
        sa.Column("patronymic", mysql.VARCHAR(length=50), nullable=True),
        sa.Column("first_name", mysql.VARCHAR(length=50), nullable=False),
        sa.Column("phone_number", mysql.VARCHAR(length=12), nullable=False),
        sa.Column("email", mysql.VARCHAR(length=50), nullable=True),
        sa.Column(
            "address_id", mysql.INTEGER(), autoincrement=False, nullable=True
        ),
        sa.ForeignKeyConstraint(
            ["address_id"], ["address.id"], name="doctor_ibfk_1"
        ),
        sa.PrimaryKeyConstraint("id"),
        mysql_collate="utf8mb4_0900_ai_ci",
        mysql_default_charset="utf8mb4",
        mysql_engine="InnoDB",
    )
    op.create_table(
        "schedule_record",
        sa.Column("id", mysql.INTEGER(), autoincrement=True, nullable=False),
        sa.Column(
            "doctor_id", mysql.INTEGER(), autoincrement=False, nullable=True
        ),
        sa.ForeignKeyConstraint(
            ["doctor_id"], ["examination.id"], name="schedule_record_ibfk_1"
        ),
        sa.PrimaryKeyConstraint("id"),
        mysql_collate="utf8mb4_0900_ai_ci",
        mysql_default_charset="utf8mb4",
        mysql_engine="InnoDB",
    )
    op.create_table(
        "pending_user",
        sa.Column("id", mysql.INTEGER(), autoincrement=True, nullable=False),
        sa.Column("username", mysql.VARCHAR(length=50), nullable=False),
        sa.Column("password", mysql.VARCHAR(length=200), nullable=False),
        sa.Column("email", mysql.VARCHAR(length=50), nullable=False),
        sa.Column("token", mysql.VARCHAR(length=50), nullable=False),
        sa.PrimaryKeyConstraint("id"),
        mysql_collate="utf8mb4_0900_ai_ci",
        mysql_default_charset="utf8mb4",
        mysql_engine="InnoDB",
    )
    op.create_index("username", "pending_user", ["username"], unique=True)
    op.create_index("token", "pending_user", ["token"], unique=True)
    op.create_index("email", "pending_user", ["email"], unique=True)
    op.create_table(
        "examination",
        sa.Column("id", mysql.INTEGER(), autoincrement=True, nullable=False),
        sa.Column("datetime", mysql.DATETIME(), nullable=False),
        sa.Column(
            "specialization_id",
            mysql.INTEGER(),
            autoincrement=False,
            nullable=True,
        ),
        sa.ForeignKeyConstraint(
            ["specialization_id"],
            ["specialization.id"],
            name="examination_ibfk_1",
        ),
        sa.PrimaryKeyConstraint("id"),
        mysql_collate="utf8mb4_0900_ai_ci",
        mysql_default_charset="utf8mb4",
        mysql_engine="InnoDB",
    )
    op.create_table(
        "user",
        sa.Column("id", mysql.INTEGER(), autoincrement=True, nullable=False),
        sa.Column("username", mysql.VARCHAR(length=50), nullable=False),
        sa.Column("password", mysql.VARCHAR(length=200), nullable=False),
        sa.Column("email", mysql.VARCHAR(length=50), nullable=False),
        sa.Column(
            "role_id", mysql.INTEGER(), autoincrement=False, nullable=True
        ),
        sa.ForeignKeyConstraint(["role_id"], ["role.id"], name="user_ibfk_1"),
        sa.PrimaryKeyConstraint("id"),
        mysql_collate="utf8mb4_0900_ai_ci",
        mysql_default_charset="utf8mb4",
        mysql_engine="InnoDB",
    )
    op.create_index("username", "user", ["username"], unique=True)
    op.create_index("email", "user", ["email"], unique=True)
    op.create_table(
        "email_token",
        sa.Column("id", mysql.INTEGER(), autoincrement=True, nullable=False),
        sa.Column("email", mysql.VARCHAR(length=50), nullable=False),
        sa.Column("token", mysql.VARCHAR(length=100), nullable=False),
        sa.Column("created_at", mysql.DATETIME(), nullable=True),
        sa.PrimaryKeyConstraint("id"),
        mysql_collate="utf8mb4_0900_ai_ci",
        mysql_default_charset="utf8mb4",
        mysql_engine="InnoDB",
    )
    op.create_index("token", "email_token", ["token"], unique=True)
    op.create_table(
        "address",
        sa.Column("id", mysql.INTEGER(), autoincrement=True, nullable=False),
        sa.Column("house", mysql.VARCHAR(length=5), nullable=False),
        sa.Column("street", mysql.VARCHAR(length=50), nullable=False),
        sa.Column("flat", mysql.VARCHAR(length=5), nullable=True),
        sa.Column("city", mysql.VARCHAR(length=50), nullable=False),
        sa.Column("region", mysql.VARCHAR(length=100), nullable=True),
        sa.Column("zip_code", mysql.VARCHAR(length=10), nullable=False),
        sa.PrimaryKeyConstraint("id"),
        mysql_collate="utf8mb4_0900_ai_ci",
        mysql_default_charset="utf8mb4",
        mysql_engine="InnoDB",
    )
    op.create_table(
        "specialization",
        sa.Column("id", mysql.INTEGER(), autoincrement=True, nullable=False),
        sa.Column("name", mysql.VARCHAR(length=50), nullable=True),
        sa.PrimaryKeyConstraint("id"),
        mysql_collate="utf8mb4_0900_ai_ci",
        mysql_default_charset="utf8mb4",
        mysql_engine="InnoDB",
    )
    # ### end Alembic commands ###
